package de.fhb.easymealtime.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import de.fhb.easymealtime.data.IRezeptDAO;
import de.fhb.easymealtime.data.RezeptDao;
import de.fhb.easymealtime.manager.IKitchen;
import de.fhb.easymealtime.manager.Kitchen;
import de.fhb.easymealtime.repository.rezeptVO;

/**
 * Servlet implementation class SearchResult
 */
@WebServlet("/SearchResult")
public class SearchResult extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SearchResult() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String keyword;
		List<rezeptVO> rezepte;
		IKitchen kitchen = new Kitchen();
		keyword = (String)request.getParameter("Suche");
		
		rezepte = kitchen.getRezept(keyword);
		
		request.setAttribute("rezepte", rezepte);
		RequestDispatcher req = request.getRequestDispatcher("SearchResult.jsp");
		req.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
